package com.gwtgeo.ui.client.defbuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ListDefBuilder<D, O> implements
		DefBuilder<List<D>, List<O>> {

	private DefBuilder<D, O> elementDefBuilder;

	public ListDefBuilder(DefBuilder<D, O> elementDefBuilder) {
		super();
		this.elementDefBuilder = elementDefBuilder;
	}

	@Override
	public List<D> buildDef(List<O> viewObjs, Map<String, Object> params) {

		List<D> defs = new ArrayList<D>();
		for (O obj : viewObjs) {
			defs.add(this.elementDefBuilder.buildDef(obj, params));
		}
		return defs;
	}

	@Override
	public List<O> buildObj(List<D> defs, Map<String, Object> params) {
		List<O> objs = new ArrayList<O>();
		for (D def : defs) {
			objs.add(this.elementDefBuilder.buildObj(def, params));
		}
		return objs;
	}

}
